﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:FIN_VOUCHER
	/// </summary>
	public partial class FIN_VOUCHER : BaseDAL<GSLMS.Entity.TB_FIN_VOUCHER>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public FIN_VOUCHER()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_FIN_VOUCHER model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_VOUWORDNUM", model.VOUWORDNUM),
								new OracleParameter("P_VOUWORD", model.VOUWORD),
								new OracleParameter("P_VOUNUM", model.VOUNUM),
								new OracleParameter("P_BUSDATE", model.BUSDATE),
								new OracleParameter("P_ACCPERIOD", model.ACCPERIOD),
								new OracleParameter("P_ANNEXNUM", model.ANNEXNUM),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTID", model.CUSTID),
								new OracleParameter("P_EMPNAME", model.EMPNAME),
								new OracleParameter("P_EMPID", model.EMPID),
								new OracleParameter("P_DEBITAMT", model.DEBITAMT),
								new OracleParameter("P_LENDERAMT", model.LENDERAMT),
								new OracleParameter("P_CREATEBY", model.CREATEBY),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_MODIFYBY", model.MODIFYBY),
								new OracleParameter("P_MODIFYDATE", model.MODIFYDATE),
								new OracleParameter("P_VOUTYPE", model.VOUTYPE),
								new OracleParameter("P_AUDITSTATUS", model.AUDITSTATUS),
								new OracleParameter("P_AUDITBY", model.AUDITBY),
								new OracleParameter("P_AUDITDATE", model.AUDITDATE)};
  
			for (int i = 0; i < 21; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_fin_voucher_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_FIN_VOUCHER model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_VOUWORDNUM", model.VOUWORDNUM),
								new OracleParameter("P_VOUWORD", model.VOUWORD),
								new OracleParameter("P_VOUNUM", model.VOUNUM),
								new OracleParameter("P_BUSDATE", model.BUSDATE),
								new OracleParameter("P_ACCPERIOD", model.ACCPERIOD),
								new OracleParameter("P_ANNEXNUM", model.ANNEXNUM),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTID", model.CUSTID),
								new OracleParameter("P_EMPNAME", model.EMPNAME),
								new OracleParameter("P_EMPID", model.EMPID),
								new OracleParameter("P_DEBITAMT", model.DEBITAMT),
								new OracleParameter("P_LENDERAMT", model.LENDERAMT),
								new OracleParameter("P_CREATEBY", model.CREATEBY),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_MODIFYBY", model.MODIFYBY),
								new OracleParameter("P_MODIFYDATE", model.MODIFYDATE),
								new OracleParameter("P_VOUTYPE", model.VOUTYPE),
								new OracleParameter("P_AUDITSTATUS", model.AUDITSTATUS),
								new OracleParameter("P_AUDITBY", model.AUDITBY),
								new OracleParameter("P_AUDITDATE", model.AUDITDATE)};
  
			for (int i = 0; i < 21; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_fin_voucher_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_fin_voucher_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_FIN_VOUCHER DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_FIN_VOUCHER model = new GSLMS.Entity.TB_FIN_VOUCHER();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["VOUWORDNUM"]!=null && dr["VOUWORDNUM"].ToString()!="")
				{
					model.VOUWORDNUM=dr["VOUWORDNUM"].ToString();
				}
				if(dr["VOUWORD"]!=null && dr["VOUWORD"].ToString()!="")
				{
					model.VOUWORD=dr["VOUWORD"].ToString();
				}
				if(dr["VOUNUM"]!=null && dr["VOUNUM"].ToString()!="")
				{
                    model.VOUNUM = OracleHelper.ToInt(dr["VOUNUM"].ToString());
				}
				if(dr["BUSDATE"]!=null && dr["BUSDATE"].ToString()!="")
				{
					model.BUSDATE=DateTime.Parse(dr["BUSDATE"].ToString());
				}
				if(dr["ACCPERIOD"]!=null && dr["ACCPERIOD"].ToString()!="")
				{
					model.ACCPERIOD=dr["ACCPERIOD"].ToString();
				}
				if(dr["ANNEXNUM"]!=null && dr["ANNEXNUM"].ToString()!="")
				{
                    model.ANNEXNUM = OracleHelper.ToInt(dr["ANNEXNUM"].ToString());
				}
				if(dr["CUSTNAME"]!=null && dr["CUSTNAME"].ToString()!="")
				{
					model.CUSTNAME=dr["CUSTNAME"].ToString();
				}
				if(dr["CUSTID"]!=null && dr["CUSTID"].ToString()!="")
				{
					model.CUSTID=OracleHelper.ToLong(dr["CUSTID"].ToString());
				}
				if(dr["EMPNAME"]!=null && dr["EMPNAME"].ToString()!="")
				{
					model.EMPNAME=dr["EMPNAME"].ToString();
				}
				if(dr["EMPID"]!=null && dr["EMPID"].ToString()!="")
				{
					model.EMPID=OracleHelper.ToLong(dr["EMPID"].ToString());
				}
				if(dr["DEBITAMT"]!=null && dr["DEBITAMT"].ToString()!="")
				{
					model.DEBITAMT=OracleHelper.ToDecimal(dr["DEBITAMT"].ToString());
				}
				if(dr["LENDERAMT"]!=null && dr["LENDERAMT"].ToString()!="")
				{
					model.LENDERAMT=OracleHelper.ToDecimal(dr["LENDERAMT"].ToString());
				}
				if(dr["CREATEBY"]!=null && dr["CREATEBY"].ToString()!="")
				{
					model.CREATEBY=dr["CREATEBY"].ToString();
				}
				if(dr["CREATEDATE"]!=null && dr["CREATEDATE"].ToString()!="")
				{
					model.CREATEDATE=DateTime.Parse(dr["CREATEDATE"].ToString());
				}
				if(dr["MODIFYBY"]!=null && dr["MODIFYBY"].ToString()!="")
				{
					model.MODIFYBY=dr["MODIFYBY"].ToString();
				}
				if(dr["MODIFYDATE"]!=null && dr["MODIFYDATE"].ToString()!="")
				{
					model.MODIFYDATE=DateTime.Parse(dr["MODIFYDATE"].ToString());
				}
				if(dr["VOUTYPE"]!=null && dr["VOUTYPE"].ToString()!="")
				{
                    model.VOUTYPE = OracleHelper.ToInt(dr["VOUTYPE"].ToString());
				}
				if(dr["AUDITSTATUS"]!=null && dr["AUDITSTATUS"].ToString()!="")
				{
                    model.AUDITSTATUS = OracleHelper.ToInt(dr["AUDITSTATUS"].ToString());
				}
				if(dr["AUDITBY"]!=null && dr["AUDITBY"].ToString()!="")
				{
					model.AUDITBY=dr["AUDITBY"].ToString();
				}
				if(dr["AUDITDATE"]!=null && dr["AUDITDATE"].ToString()!="")
				{
					model.AUDITDATE=DateTime.Parse(dr["AUDITDATE"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_FIN_VOUCHER GetByID(long ID)
		{
			GSLMS.Entity.TB_FIN_VOUCHER sModel = new GSLMS.Entity.TB_FIN_VOUCHER();
			string sql = "";
			sql = "select * from TB_FIN_VOUCHER where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_FIN_VOUCHER> GetList(GSLMS.Entity.TB_FIN_VOUCHER searchParam)
		{
			var list=new List<GSLMS.Entity.TB_FIN_VOUCHER>();
			DataTable dt = null;
			string tblName = "TB_FIN_VOUCHER";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_FIN_VOUCHER model = new GSLMS.Entity.TB_FIN_VOUCHER();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

